﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using HighSign.Common.Plugins;

namespace HighSign.CorePlugins
{
	public class NextApplication : IPlugin
	{
		#region Private Variables

		IHostControl _HostControl = null;

		#endregion

		#region IAction Properties

		public string Name
		{
			get { return "Next Application"; }
		}

		public string Description
		{
			get { return "Switches to the next application (Same as Alt + Tab)"; }
		}

		public Form GUI
		{
			get { return null; }
		}

		public string Category
		{
			get { return "Windows"; }
		}

		public bool IsAction
		{
			get { return true; }
		}

		#endregion

		#region IAction Methods

		public void Initialize()
		{

		}

		public bool Gestured(PointInfo ActionPoint)
		{
			//if (ActionPoint.WindowHandle.ToInt64() != ManagedWinapi.Windows.SystemWindow.ForegroundWindow.HWnd.ToInt64())
			//	ManagedWinapi.Windows.SystemWindow.ForegroundWindow = ActionPoint.Window;

			ManagedWinapi.KeyboardKey altKey = new ManagedWinapi.KeyboardKey(Keys.LMenu);
			ManagedWinapi.KeyboardKey shiftKey = new ManagedWinapi.KeyboardKey(Keys.Shift);
			ManagedWinapi.KeyboardKey tabKey = new ManagedWinapi.KeyboardKey(Keys.Tab);

			altKey.Press();
			shiftKey.Press();
			tabKey.PressAndRelease();

			System.Threading.Thread.Sleep(100);

			shiftKey.Release();
			altKey.Release();

			return true;
		}

		public void Deserialize(string SerializedData)
		{
			// Nothing to deserialize
		}

		public string Serialize()
		{
			// Nothing to serialize, send empty string
			return "";
		}

		public void ShowGUI(bool IsNew)
		{
			// Nothing to do here
		}

		#endregion

		#region Host Control

		public IHostControl HostControl
		{
			get { return _HostControl; }
			set { _HostControl = value; }
		}

		#endregion
	}
}